package com.homestay.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.homestay.beans.HouseInfoBean;
import com.homestay.service.IHouseInfoService;
import com.homestay.vo.PageInfo;

@Controller
public class HouseInfoController {

	@Autowired
	private IHouseInfoService houseInfoService;
	
	private static int totalCount;
	
	/**
	 * 获取房源总数和总页数
	 * @return
	 */
	@RequestMapping("/getHouseByPage.action")
	@ResponseBody
	public PageInfo<HouseInfoBean> getHouseByPage(@RequestBody PageInfo<HouseInfoBean> pageInfo){
		
		totalCount++;
		System.out.println("==================第"+totalCount+"次请求开始===================");
		System.out.println(pageInfo);
		//获得数据库中的总记录数
		int count = houseInfoService.getHouseTotalCount(pageInfo);
		pageInfo.setTotalCount(count);
		
		List<HouseInfoBean> houseInfoList = houseInfoService.getHouseByPage(pageInfo);
		System.out.println(houseInfoList);
		pageInfo.setListT(houseInfoList);
		System.out.println(pageInfo);
		System.out.println(pageInfo.getListT().size());
		System.out.println("==================第"+totalCount+"次请求结束===================");
		return pageInfo;
	}
	
	/**
	 * 获取房源名称和经纬度信息
	 * @return
	 */
	@RequestMapping("/getLocation.action")
	@ResponseBody
	public List<Map<String, Object>> getLocation(){
		List<Map<String, Object>> list=houseInfoService.getLocation();
		//System.out.println("测试是否成功"+list);
		//System.out.println(list.get(0).get("h_name"));
		//System.out.println(list.get(0).get("h_longitude")+","+list.get(0).get("h_latitude"));
		return list;
	}
	
}
